/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kweative.network;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;

/**
 *
 * @author henrik
 */
public class HttpCookie {
    private String name = "";
    private String value = "";
    private Date expires = null;
    private String path = "/";
    private String domain = "";
    private boolean secure = false;

    public HttpCookie(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public Date getExpires() {
        return expires;
    }

    public void setExpires(Date expires) {
        this.expires = expires;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public boolean isSecure() {
        return secure;
    }

    public void setSecure(boolean secure) {
        this.secure = secure;
    }
    

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getName()).append("=").append(getValue()).append("; ");
        if (getExpires() != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss zzz");
            dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
            sb.append("expires=")
                    .append(dateFormat.format(getExpires()))
                    .append("; ");
        }
        if (!getPath().isEmpty()) {
            sb.append("path=").append(getPath()).append("; ");
        }
        if (!getDomain().isEmpty()) {
            sb.append("domain=").append(getDomain()).append("; ");
        }
        if (isSecure()) {
            sb.append("secure");
        }
        return sb.toString();
    }

}
